package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.OrderDetailDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.OrderDetail;
import com.zy.pojo.query.bs.OrderDetailQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.OrderDetailService;
import com.zy.utils.DateUtil;

@Service("orderDetailService")
public class OrderDetailServiceImpl extends BaseServiceImpl<OrderDetail> implements OrderDetailService {

	@Autowired
	private OrderDetailDao orderDetailDao;

	@Override
	public PageVo pageOrderDetail(OrderDetailQuery orderDetailQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.orderDetailDao.countOrderDetail(orderDetailQuery), this.orderDetailDao.listOrderDetail(orderDetailQuery, start, limit));
	}

	@Override
	public void saveOrderDetail(OrderDetail orderDetail) {
		long time = DateUtil.getTime();
		orderDetail.setCreateTime(time);
		orderDetail.setModifyTime(time);
		orderDetail.setStatus(StatusEnum.NORMAL.getValue());
		this.orderDetailDao.save(orderDetail);
	}
	
	@Override
	public void updateOrderDetail(OrderDetail orderDetail) {
		orderDetail.setModifyTime(DateUtil.getTime());
		this.orderDetailDao.updateByPrimaryKeySelective(orderDetail);
	}

	@Override
	public void removeOrderDetail(long id) {
		try {
			this.orderDetailDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			OrderDetail orderDetail = new OrderDetail();
			orderDetail.setId(id);
			orderDetail.setModifyTime(DateUtil.getTime());
			orderDetail.setStatus(StatusEnum.DELETE.getValue());
			this.orderDetailDao.updateByPrimaryKeySelective(orderDetail);
		}
	}

	@Override
	public void recover(long id) {
		OrderDetail orderDetail = new OrderDetail();
		orderDetail.setId(id);
		orderDetail.setModifyTime(DateUtil.getTime());
		orderDetail.setStatus(StatusEnum.NORMAL.getValue());
		this.orderDetailDao.updateByPrimaryKeySelective(orderDetail);
	}

}
